Skip to content

Prototype browser/WASM validation in isolated workers - #538

Draft
robgruen wants to merge 6 commits into
mainfrom
agents/since-you-ve-looked-into-it-th-emost
Draft

robgruen wants to merge 6 commits into
mainfrom
agents/since-you-ve-looked-into-it-th-emost

Conversation

@robgruen

@robgruen robgruen commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Draft investigation for #536, under #534. This is an opt-in prototype for design review, not a supported browser release or a request to merge an experimental compiler into main.

  • Add a separate, private experimental browser package outside the normal npm workspaces. The default Node compiler, dependency manifest, and public entry points are unchanged.
  • Extract shared schema generation, enum normalization, preflight, and diagnostic logic rather than duplicate or weaken validation. Keep separately typed adapters for the native and experimental compiler APIs.
  • Pin matching compiler/WASM artifacts to 7.1.0-dev.20261030.1; verify version, length, and SHA-256 before compiling. Make loading, cancellation, errors, independent validator ownership, and disposal explicit.
  • Add a runnable application-owned, one-job-per-worker example. Cancellation terminates the owned worker and rejects its promise, including during synchronous validation. There is no public worker-pool API, silent fallback, or hidden retry.
  • Add cross-backend parity and real Chromium/Firefox/WebKit tests, slow-download checks, worker lifecycle coverage, and broader performance/memory measurements.

The shared refactor was reviewed before adding the worker example. The minimal library, enum wire mapping, diagnostic normalization, and model protocol definitions remain unchanged; existing native diagnostic and CJS/ESM compatibility tests cover the new internal boundary.

Verification

Windows, Node.js 24.22.1, after integrating main's opt-in live-test work:

  • typescript: npm run build-all and npm test with TYPECHAT_LIVE_TESTS=0 -- 424 ordinary tests passed; the live API suite remained disabled.
  • Experimental checks were rerun together with TYPECHAT_STABILITY_BROWSERS=1: 34 passed, 2 failed, 0 skipped. The two failures independently assert the declared Unicode enum value on stable native and pinned WASM; they remain explicit shipping gates. The 58-outcome compatibility corpus still passes, demonstrating why parity alone is insufficient.
  • The combined run includes 3 passing browser-matrix suites, 3 passing hosted-page CSP/cache suites, 3 passing worker-recovery suites, and 4 HTTP hosting-contract tests. Browser coverage is Chromium 149.0.7827.55, Firefox 151.0, and Playwright WebKit 26.5.
  • Each engine ran the 58-case corpus, the example UI, ten worker lifecycle/error checks, cancellation after a partial network response, concurrent job isolation, termination during validation, and all-worker cleanup.
  • A 500-property schema was validated 250 times in a worker while the main-thread heartbeat continued.
  • Compiler-version mismatch, HTTP/network/abort/size/integrity errors, and explicit disposal were tested.
  • git diff --check passed.

All model responses were synthetic. No live model calls or credentials were used. Tests manage and close their own browsers, workers, and loopback servers.

Browser hosting follow-up

  • The application-owned example now uses a shared, tested static handler; no hosting API was added to the TypeChat core and nothing was deployed externally.
  • HTML/UI scripts/styles are external and no-store. Strict CSP permits same-origin resources and wasm-unsafe-eval, not general JavaScript eval or inline scripts/styles. Both the document and worker receive the policy. Real-page eval blocking and explicit failure without WASM permission pass in all three engines.
  • The compiler asset URL includes its exact version and SHA-256. Startup verifies the bytes before serving it with immutable caching, gzip/identity negotiation, representation-specific ETags, Vary: Accept-Encoding, and correct HEAD/304/error handling.
  • Four protocol tests verify actual bytes, MIME types, cache headers, compression, conditional responses, and encoding/method errors. Existing browser and recovery fixtures use the same hosting handler.
  • Automated two-job checks observed a warm cache hit in Firefox; Chromium and WebKit fetched again. Every network artifact response was gzip (13,359,431 bytes). Cache headers make reuse possible but do not guarantee storage, prevent eviction, or avoid initialization in a new worker.

This follow-up changes only the private experiment's example, tests, and documentation. Library validation and dependency manifests remain unchanged; the separate Unicode gates are still failing rather than suppressed.

Follow-up findings and remaining conformance blocker

  • Fixed: a retained closed validator previously kept its compiled WASM module alive through the loader context. Moving validator closure construction to a module-level helper removes that strong retaining path. The heap-reference regression fails before the fix and passes afterwards; reactor and linear-memory disposal also pass.
  • Pre-existing Unicode issue: the valid enum value containing U+D800 followed by U+FEFF and x is rejected by both backends. It also reproduces on an untouched main snapshot at 0ef51b0, before this refactor. All 21 library source/runtime-manifest files were verified against that commit, allowing only Git's Windows line-ending conversion. Original build and the leading-BOM control pass; the declared lone-surrogate/BOM value fails after successful schema preflight.
  • Portable TypeChat reproduction is prepared for the existing microsoft/TypeScript#65458. No separate upstream comment or PR was posted. No decoder patch, dependency upgrade, relaxed validation, skipped conformance assertion, or silent fallback was introduced.
  • Retail Firefox confirmation: official Mozilla Windows x64/en-US 151.0, verified SHA-512 manifest and valid Mozilla signatures, fresh profiles, no Juggler resources or debugger connection. Three dedicated-worker runs used the identical fixed compiler and 500-property x250 workload; valid/invalid/recovery/after-close controls all passed. Retail BuildID 20260516144017 differs from Playwright's 20260611193205. This does not certify WAN/mobile performance, retail memory costs, or a full retail-browser matrix.

Ordinary repository CI does not run this separately installed experimental suite. Its green result must not hide the two known failing semantic gates. This remains a draft investigation, not a merge-ready implementation.

Important limits / not ready for main

  • The upstream WASM API is experimental; publication is not a stability guarantee. See microsoft/TypeScript#64174.
  • The artifact is about 52.6 MB raw / 13.4 MB gzipped, plus about 441 KB raw / 94 KB gzipped library JavaScript.
  • The original roughly 19.4-second automated Firefox result is not representative of the tested retail build. Official retail Firefox 151.0, with an unobserved dedicated worker and the same workload/library, took 2.141 / 2.180 / 2.161 seconds. The Playwright debugger is a confound; differing BuildIDs and the small one-host sample limit pure-causal/general performance claims.
  • Sampled instrumented Playwright browser-process-tree working-set sums reached approximately 0.86-1.10 GB after the preceding corpus/lifecycle probes. These sums include runtime overhead and may double-count shared pages; they are not one-job incremental memory or precise peaks. Retail Firefox memory was not reprofiled.
  • Playwright WebKit on Windows does not certify Safari. macOS/mobile/low-memory devices, production CSPs, and real edge runtimes remain unverified.
  • This package intentionally omits the Node HTTP/proxy client and program/interactive helpers. It does not silently bypass proxy configuration or make the existing public typechat/ts entry point browser-compatible.

The prototype README documents reproducible commands, measured results, provisional budgets, lifecycle trade-offs, upgrade/rollback, and outstanding merge gates:
Browser prototype README.

Keep #534 and #536 open. Any supported mainline integration still needs explicit upstream-stability/maintenance, API, performance, and compatibility decisions.

robgruen and others added 5 commits November 23, 2026 16:20
Preserve the opt-in investigation for #536 before reviewing the shared refactor and expanding worker/browser coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add an application-owned worker example, Chromium/Firefox/WebKit coverage, explicit cancellation and cleanup checks, and broader performance and process-memory measurements for #536.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Retain the opt-in live-test work while keeping this browser prototype isolated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Document the 424 passing ordinary tests, disabled live suite, and both browser memory ceilings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Eliminate the closed-validator compiled-module retaining path. Add independent stability and Unicode regressions, confirm the Unicode failure on pristine main, and document the verified retail Firefox dedicated-worker comparison. Keep the two upstream conformance failures explicit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep hosting application-owned. Verify CSP, compressed immutable artifacts, encoding negotiation, conditional requests, and worker loading errors across the browser matrix. Preserve the separate Unicode conformance gates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
}
const qualities = new Map();
for (const entry of header.split(",")) {
const match = /^\s*([a-z0-9!#$%&'*+.^_`|~-]+)\s*(?:;\s*q\s*=\s*(0(?:\.\d{0,3})?|1(?:\.0{0,3})?))?\s*$/i.exec(entry);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants